Assignment 4

Author

Jack Reilly

Part 1. Lines

1 - 3: We’re going do draw all things in the same R block here.

plot(x=0, 
     type='n', 
     xlim=c(-20,20), 
     ylim=c(-20,20),
     xlab="This is the X axis", 
     ylab="This is the Y axis", 
     main="My Line")

abline(h=0, v=0, col = "gray")

abline(a=3, 
       b=4, 
       col = "forestgreen", 
       lwd=3, 
       lty = "dashed")

text(5,12, "y=4x+3", col = "forestgreen")

4. Here are some rainbows.

plot(x=0, type='n', xlim=c(-10,10), ylim=c(-10,10), xlab="x", ylab="y", main="Drawing Some Lines")
abline(h=0, v=0, col = "gray")

abline(a=0, b=1, col = "purple", lwd=110)
abline(a=0, b=-1, col = "purple", lwd=110)

abline(a=0, b=1, col = "blue", lwd=100)
abline(a=0, b=-1, col = "blue", lwd=100)

abline(a=0, b=1, col = "green", lwd=90)
abline(a=0, b=-1, col = "green", lwd=90)

abline(a=0, b=1, col = "yellow", lwd=80)
abline(a=0, b=-1, col = "yellow", lwd=80)

abline(a=0, b=1, col = "orange", lwd=70)
abline(a=0, b=-1, col = "orange", lwd=70)

abline(a=0, b=1, col = "red", lwd=60)
abline(a=0, b=-1, col = "red", lwd=60)

abline(a=0, b=1, col = "white", lwd=50)
abline(a=0, b=-1, col = "white", lwd=50)

abline(a=0, b=1, col = "orange", lwd=50)
abline(a=0, b=-1, col = "orange", lwd=50)

abline(a=0, b=1, col = "yellow", lwd=40)
abline(a=0, b=-1, col = "yellow", lwd=40)

abline(a=0, b=1, col = "green", lwd=30)
abline(a=0, b=-1, col = "green", lwd=30)

abline(a=0, b=1, col = "blue", lwd=20)
abline(a=0, b=-1, col = "blue", lwd=20)

abline(a=0, b=1, col = "purple", lwd=10)
abline(a=0, b=-1, col = "purple", lwd=10)

abline(a=0, b=1, col = "black", lwd=5, lty="dotted")
abline(a=0, b=-1, col = "black", lwd=5, lty="dotted")

Part 2. Protected Lands

1. Descriptive statistics

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
lands<-read_csv("datasets/protected_lands.csv")
New names:
Rows: 13 Columns: 7
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(2): country, country_code dbl (4): protected_lands, gdp_percap,
tot_gdp_bilions, ...6 lgl (1): ...7
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...6`
• `` -> `...7`
mean(lands$protected_lands)
[1] 18.38462
mean(lands$gdp_percap)
[1] 25210.38
mean(lands$tot_gdp_bilions)
[1] 1125.923
sd(lands$protected_lands)
[1] 10.89754
sd(lands$gdp_percap)
[1] 19337.7
sd(lands$tot_gdp_bilions)
[1] 3056.297
range(lands$protected_lands)
[1]  4 42
range(lands$gdp_percap)
[1]  3156 58553
range(lands$tot_gdp_bilions)
[1]    20 11199

2 - 7: Scatterplots, regression, and final plot.

plot(x=0, type='n', xlim=c(0,12000), ylim=c(0,50), xlab="Total GDP", ylab="Protected Lands", main="Protected Lands by Country GDP")
points(y=lands$protected_lands, x=lands$tot_gdp_bilions, pch=20)

model_tot<-lm(lands$protected_lands~lands$tot_gdp_bilions)

abline(model_tot, col="red", lwd=2)

plot(x=0, type='n', xlim=c(3000,60000), ylim=c(0,50), xlab="GDP Per Capita", ylab="Protected Lands", main="Protected Lands by Country GDP Per Capita")
points(y=lands$protected_lands, x=lands$gdp_percap, pch=20)

model_pc<-lm(lands$protected_lands~lands$gdp_percap)

abline(model_pc, col="red", lwd=2)